package com.lovo.ssc.controller;

import com.lovo.ssc.service.impl.CartService;
import com.lovo.ssc.vo.Cart;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 购物车控制器
 * @author WXL
 * @date 2022/7/7
 */
@RestController
@RequestMapping("/cart")
@Api(tags = "购物车---王孝亮")
public class CartController {

    @Autowired
    private CartService service;

    @ApiOperation("查看购物车商品")
    @GetMapping("findByCart")
    public Cart findByCart(){
        return service.findByCart();
    }

    @ApiOperation("添加购物车商品")
    @PostMapping("addGoods/{goodsCode}/{buyNum}")
    public void addGoods(@PathVariable String goodsCode,@PathVariable int buyNum){
        service.addToCart(goodsCode, buyNum);
    }

    @ApiOperation("按编号删除购物车商品")
    @DeleteMapping("delGoodsById/{goodsCode}")
    public void delGoodsById(@PathVariable String goodsCode){
        service.delGoodsById(goodsCode);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("clearCart")
    public void clearCart(){
        service.clearCart();
    }

    @ApiOperation("按编号修改购物车商品数量")
    @PutMapping("updateGoodsNumById/{goodsCode}/{buyNum}")
    public void updateGoodsNumById(@PathVariable String goodsCode,@PathVariable int buyNum){
        service.updateGoodsNumById(goodsCode,buyNum);
    }

    @ApiOperation("更改购物项选中状态")
    @PutMapping("updateCheck/{goodsCode}/{check}")
    public void updateCheck(@PathVariable String goodsCode,@PathVariable boolean check){
        service.updateCheck(goodsCode, check);
    }
}
